package com.cold.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cold.common.domain.AlertMessage;
import com.cold.manage.service.IAlertMessageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cold.common.annotation.Log;
import com.cold.common.core.controller.BaseController;
import com.cold.common.core.domain.AjaxResult;
import com.cold.common.enums.BusinessType;
import com.cold.common.utils.poi.ExcelUtil;
import com.cold.common.core.page.TableDataInfo;

/**
 * 报警消息Controller
 * 
 * @author cold
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/manage/message")
public class AlertMessageController extends BaseController
{
    @Autowired
    private IAlertMessageService alertMessageService;

    /**
     * 查询报警消息列表
     */
    @PreAuthorize("@ss.hasPermi('system:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlertMessage alertMessage)
    {
        startPage();
        List<AlertMessage> list = alertMessageService.selectAlertMessageList(alertMessage);
        return getDataTable(list);
    }

    /**
     * 导出报警消息列表
     */
    @PreAuthorize("@ss.hasPermi('system:message:export')")
    @Log(title = "报警消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlertMessage alertMessage)
    {
        List<AlertMessage> list = alertMessageService.selectAlertMessageList(alertMessage);
        ExcelUtil<AlertMessage> util = new ExcelUtil<AlertMessage>(AlertMessage.class);
        util.exportExcel(response, list, "报警消息数据");
    }

    /**
     * 获取报警消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(alertMessageService.selectAlertMessageById(id));
    }

    /**
     * 新增报警消息
     */
    @PreAuthorize("@ss.hasPermi('system:message:add')")
    @Log(title = "报警消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlertMessage alertMessage)
    {
        return toAjax(alertMessageService.insertAlertMessage(alertMessage));
    }

    /**
     * 修改报警消息
     */
    @PreAuthorize("@ss.hasPermi('system:message:edit')")
    @Log(title = "报警消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlertMessage alertMessage)
    {
        return toAjax(alertMessageService.updateAlertMessage(alertMessage));
    }

    /**
     * 删除报警消息
     */
    @PreAuthorize("@ss.hasPermi('system:message:remove')")
    @Log(title = "报警消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alertMessageService.deleteAlertMessageByIds(ids));
    }
}
